function formatDate(value, args) {
	var dt = new Date(value);
	if (args == 'yyyy-M-d') { // yyyy-M-d
		let year = dt.getFullYear();
		let month = dt.getMonth() + 1;
		let date = dt.getDate();
		return `${year}-${month}-${date}`;
	} else if (args == 'yyyy-M-d H:m:s') { // yyyy-M-d H:m:s
		let year = dt.getFullYear();
		let month = dt.getMonth() + 1;
		let date = dt.getDate();
		let hour = dt.getHours();
		let minute = dt.getMinutes();
		let second = dt.getSeconds();
		return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
	} else if (args == 'yyyy-MM-dd') { // yyyy-MM-dd
		let year = dt.getFullYear();
		let month = (dt.getMonth() + 1).toString().padStart(2, '0');
		let date = dt.getDate().toString().padStart(2, '0');
		return `${year}-${month}-${date}`;
	} else if (args == 'yyyy年MM月dd日') { // yyyy-MM-dd
		let year = dt.getFullYear();
		let month = (dt.getMonth() + 1).toString().padStart(2, '0');
		let date = dt.getDate().toString().padStart(2, '0');
		return `${year}年${month}月${date}日`;
	} else if (args == 'MM月dd日') { // yyyy-MM-dd
		let month = (dt.getMonth() + 1).toString().padStart(2, '0');
		let date = dt.getDate().toString().padStart(2, '0');
		return `${month}月${date}日`;
	} else { // yyyy-MM-dd HH:mm:ss
		let year = dt.getFullYear();
		let month = (dt.getMonth() + 1).toString().padStart(2, '0');
		let date = dt.getDate().toString().padStart(2, '0');
		let hour = dt.getHours().toString().padStart(2, '0');
		let minute = dt.getMinutes().toString().padStart(2, '0');
		let second = dt.getSeconds().toString().padStart(2, '0');
		return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
	}
}
function isBlank(data) {
	return data === null || data === '' || data === undefined || data === 'undefined' || data === 'null';
}

function isNotBlank(data) {
	return !isBlank(data);
}

function isEmpty(data) {
	return isBlank(data) || data.length === 0;
}

function isNotEmpty(data) {
	return !isEmpty(data);
}

function getCurrentDate(date) {
	if (isBlank(date)) {
		date = new Date();
	}
	let year = date.getFullYear();
	let month = ('0' + (date.getMonth() + 1));
	let day = ('0' + date.getDate());
	return year + '-' + month.substring(month.length - 2, month.length) + '-' + day.substring(day.length - 2, day
		.length);
}

function getCurrentDateLastNum(num, date) {
	if (isBlank(date)) {
		date = new Date();
	}
	date.setDate(date.getDate() + num);
	let year = date.getFullYear();
	let month = ('0' + (date.getMonth() + 1));
	let day = ('0' + date.getDate());
	return year + '-' + month.substring(month.length - 2, month.length) + '-' + day.substring(day.length - 2, day
		.length);
}

function getCurrentDateTime() {
	let date = new Date();
	let year = date.getFullYear();
	let month = ('0' + (date.getMonth() + 1));
	let day = ('0' + date.getDate());
	let hour = '0' + date.getHours();
	let minute = '0' + date.getMinutes();
	let second = '0' + date.getSeconds();
	return year + '-' + month.substring(month.length - 2, month.length) + '-' + day.substring(day.length - 2, day
		.length) + ' ' + hour.substring(hour.length - 2, hour.length) + ':' + minute.substring(minute.length - 2,
		minute.length) + ':' + second.substring(second.length - 2, second.length);
}

function compareDateTime(begin, end) {
	if (isBlank(end)) {
		end = getCurrentDateTime();
	}
	begin = begin.replace("-", "/").replace("-", "/");
	end = end.replace("-", "/").replace("-", "/");
	return new Date(end).getTime() - new Date(begin).getTime();
}

function getCurrentMonthFirst() {
	let date = new Date();
	date.setDate(1);
	let month = date.getMonth() + 1;
	let day = date.getDate();
	month = month < 10 ? '0' + month : month;
	day = day < 10 ? '0' + day : day;
	return date.getFullYear() + '-' + month + '-' + day
}

function getRandom(num) {
	var s = '';
	var randomNum = function() {
		var n = Math.floor(Math.random() * 62);
		if (n < 10) return n; //1-10
		if (n < 36) return String.fromCharCode(n + 55); //A-Z
		return String.fromCharCode(n + 61); //a-z
	}
	while (s.length < num) s += randomNum();
	return s;
}

function getCurrentMonthLast() {
	let date = new Date();
	let year = date.getFullYear();
	let month = date.getMonth() + 1;
	month = month < 10 ? '0' + month : month;
	let day = new Date(year, month, 0);
	return year + '-' + month + '-' + day.getDate()
}

function copyProperty(src, des) {
	if (isNotBlank(src)) {
		let properties = Object.getOwnPropertyNames(src);
		for (let i = 0; i < properties.length; i++) {
			let property = properties[i];
			if (Object.prototype.hasOwnProperty.call(des, property)) {
				if (des[property] instanceof Array) {
					if (src[property] instanceof Array) {
						des[property] = src[property];
					} else {
						if (isBlank(src[property])) {
							des[property] = [];
						} else {
							des[property] = src[property].split(',');
						}
					}
				} else {
					if (isBlank(src[property])) {
						des[property] = '';
					} else {
						des[property] = src[property];
					}
				}
			} else {
				des[property] = src[property];
			}
		}
	}
}

export function getUrlKey(url, name) {
	return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(url) || [, ''])[1].replace(
		/\+/g, '%20')) || null
}

export function toFixed(num) {
	return Math.round((num + Number.EPSILON) * 100) / 100;
}
//获取年龄
export function getIdCardAge(card) {
	let birthday = this.getIdCardBirthday(card);
	var age = 0,
		yearBirth, monthBirth, dayBirth;
	if (this.isNotEmpty(birthday)) {
		let list = birthday.split("-");
		if (list.length == 3) {
			yearBirth = list[0];
			monthBirth = list[0];
			dayBirth = list[0];
			//获取当前年月日并计算年龄
			var myDate = new Date();
			var monthNow = myDate.getMonth() + 1;
			var dayNow = myDate.getDate();
			var age = myDate.getFullYear() - yearBirth;
			if (monthNow < monthBirth || (monthNow == monthBirth && dayNow < dayBirth)) {
				age--;
			}
			//返回年龄
			return age;
		}
		return '';
	}
	return '';
}
//获取出生日期
export function getIdCardBirthday(userCard) {
	if (this.checkIdCard(userCard)) {
		var yearBirth, monthBirth, dayBirth;
		if (userCard.length == 15) {
			var org_birthday = userCard.substring(6, 12);
			//获取出生年月日
			yearBirth = "19" + org_birthday.substring(0, 2);
			monthBirth = org_birthday.substring(2, 4);
			dayBirth = org_birthday.substring(4, 6);
		} else if (userCard.length == 18) {
			//获取出生年月日
			yearBirth = userCard.substring(6, 10);
			monthBirth = userCard.substring(10, 12);
			dayBirth = userCard.substring(12, 14);
		}
		return yearBirth + "-" + monthBirth + "-" + dayBirth;
	} else {

		return "";
	}
};

//校验位的检测
export function checkIdCard(card) {
	var reg = /(^\d{15}$)|(^\d{17}([0-9]|X)$)/; //验证身份证号码的正则
	if (card.length == '15') {
		var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
		var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
		var cardTemp = 0,
			i;
		card = card.substr(0, 6) + '19' + card.substr(6, card.length - 6);
		for (i = 0; i < 17; i++) {
			cardTemp += card.substr(i, 1) * arrInt[i];
		}
		card += arrCh[cardTemp % 11];
	}
	var len = card.length;
	if (len == '18') {
		var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
		var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
		var cardTemp = 0,
			i, valnum;
		for (i = 0; i < 17; i++) {
			cardTemp += card.substr(i, 1) * arrInt[i];
		}
		valnum = arrCh[cardTemp % 11];
		if (valnum == card.substr(17, 1)) {
			return true;
		}
		return false;
	}
	return false;
};


export default {
	getIdCardBirthday,
	getIdCardAge,
	checkIdCard,
	getCurrentDateLastNum,
	toFixed,
	getUrlKey,
	compareDateTime,
	getCurrentDateTime,
	copyProperty,
	isBlank,
	isNotBlank,
	isEmpty,
	isNotEmpty,
	getCurrentDate,
	getCurrentMonthFirst,
	getRandom,
	getCurrentMonthLast,
	formatDate
}
